##
## Build the memento.xpi file
##

APPNAME=memento
BUILDDIR=build

#JARFILE=$(APPNAME).jar
BUILDNUM=$(shell date '+%Y-%m-%d-%H%M')
XPIFILE=release/$(APPNAME)-$(BUILDNUM).xpi
TGZFILE=release/$(APPNAME)-$(BUILDNUM)-src.tar.gz

MANIFESTFILE := chrome.manifest
INSTALLFILE  := install.rdf
CHROMEFILES     := $(wildcard chrome/content/* chrome/locale/*/*)
COMPONENTFILES  := $(wildcard components/*)
DEFAULTSFILES   := $(wildcard defaults/*/*)
INTERFACESFILES := $(wildcard interfaces/*.xul)

#$(info $(CHROMEFILES))

all: xpi archive

ifeq ($(MAKECMDLINE),clean)
	skipdeps := true
endif

ifndef skipdeps
include .deps
endif

clean:
	rm -fr .deps build release

archive: .deps dirs $(TGZFILE)

$(TGZFILE):
	bin/createArchive $(TGZFILE)

xpi: .deps dirs $(XPIFILE)

$(XPIFILE): $(MANIFESTFILE:%=build/%) $(INSTALLFILE:%=build/%) \
            $(CHROMEFILES:%=build/%) \
            $(COMPONENTFILES:%=build/%) \
            $(DEFAULTSFILES:%=build/%) \
            $(INTERFACESFILES:%=build/%) \
            Makefile
	rm -f $(XPIFILE)
	cd build  &&  zip -0DXqr ../$(XPIFILE) *



upload:
	scp -p *.xpi fast:~/public_html/memento/releases/

	@mkdir -p build/chrome/content
	@mkdir -p build/chrome/locale/en-US
	@mkdir -p build/components
	@mkdir -p build/defaults/preferences
	@mkdir -p build/interfaceinterfaces
	@mkdir -p release

.deps: $(CHROMEFILES) $(COMPONENTFILES) $(DEFAULTSFILES) $(INTERFACESFILES) \
       bin/makeDependencies.sh
	bash bin/makeDependencies.sh >.deps

#eof
